﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TabletopWidgetTestApp
{
    /// <summary>
    /// Interaction logic for BorderMenu.xaml
    /// </summary>
    public partial class BorderMenu : Grid
    {
        private string orientation;

        public MainWindow parent;

        public BorderMenu()
        {
            InitializeComponent();
        }
        
        public void SwitchOrientation(string Orientation)
        {
            orientation = Orientation;
            if (Orientation == "Down")
            {
                SetOrientation(0);
                this.HorizontalAlignment = HorizontalAlignment.Stretch;
                //this.HorizontalAlignment = HorizontalAlignment.Center;

                this.VerticalAlignment = VerticalAlignment.Bottom;
                Canvas.SetBottom(this, 0);
            }
            if (Orientation == "Right")
            {
                SetOrientation(-90);
                this.VerticalAlignment = VerticalAlignment.Stretch;
                //this.VerticalAlignment = VerticalAlignment.Center;

                this.HorizontalAlignment = HorizontalAlignment.Right;
                Canvas.SetRight(this, 0);
            }
            if (Orientation == "Up")
            {
                SetOrientation(180);
                this.HorizontalAlignment = HorizontalAlignment.Stretch;
                //this.HorizontalAlignment = HorizontalAlignment.Center;
                this.VerticalAlignment = VerticalAlignment.Top;
                Canvas.SetTop(this, 0);
            }
            if (Orientation == "Left")
            {
                SetOrientation(90);
                this.VerticalAlignment = VerticalAlignment.Stretch;
                //this.VerticalAlignment = VerticalAlignment.Center;
                this.HorizontalAlignment = HorizontalAlignment.Left;
                Canvas.SetLeft(this, 0);
            }
        }
        public void SetPosition(double x, double y, double actualWidth, double actualHeight)
        {
            if (orientation == "Up" || orientation == "Down")
            {
                //Canvas.SetLeft(this, x);
                Margin = new Thickness(x, 0, actualWidth - x, 0);
            }
            else if (orientation == "Left" || orientation == "Right")
            {
                //Canvas.SetTop(this, y);
                Margin = new Thickness(0, y, 0, actualHeight - y);
            }
        }

        private void SetOrientation(double angle)
        {
            Layer0.Orientation = angle;
            Layer1.Orientation = angle;
        }
        private void Quit(object sender, RoutedEventArgs e)
        {
            Environment.Exit(0);
        }

        private void makeWindow(object sender, RoutedEventArgs e)
        {
            parent.addRNTWindow(0, 0);
            Visibility = System.Windows.Visibility.Collapsed;
        }
    }
}
